/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fiu.accesslog.filter;

import edu.fiu.accesslog.SingleAccessLog;
import java.util.ArrayList;

/**
 *
 * @author Hasan Mahmud @date Jul 8, 2012
 */
public class AccessLogFilter extends Filters
{

        
        private ArrayList <Filters> filters;
        
        
        
        private static AccessLogFilter singletonInstance = null;

        
        
        public static synchronized AccessLogFilter getInstance()
        {
                if (singletonInstance == null)
                {
                        singletonInstance = new AccessLogFilter();
                }

                return singletonInstance;
        }
        
        private String regFilteredIPs[] = new String[]
        {
                "131.94.*.*"
        };
        
        private String simpleFilteredIPs[] = new String[]
        {
                 
//                //MSN bot
//                "207.46.195.159",
//                "65.52.109.198",
//                "157.55.18.25",
//                "157.55.16.222",
//                "65.52.108.12",
//                "207.46.199.55",
//                "207.46.204.234",
//                "65.52.108.69",
//                
//                //FAST Search & Transfer Inc
//                "208.68.143.203",
//                "208.68.138.5",
//                
//                //Googlebot
//                "66.249.71.118",
//                "66.249.71.199",
//                
                //Siteimprove A-S
                "93.160.60.22" ,
//                
//                //Yandex Inc
//                "199.21.99.75",
//                
//                //Dotbot
//                "208.115.113.88",
//                "208.115.111.72",
        };
        
        
        private AccessLogFilter()
        {
                filters = new ArrayList<Filters>(10);
                
                
                IPFilters  ipFilter = IPFilters.getInstance();
                for (String ipToFilter:simpleFilteredIPs)
                {
                        ipFilter.addSimpleIPforFilter(ipToFilter);
                }
                
                 for (String ipToFilter:regFilteredIPs)
                {
                        ipFilter.addRExpressedIPforFilter(ipToFilter);
                }
                 filters.add(ipFilter);
                 
                 filters.add(BotFilters.getInstance());

        }

        @Override
        public boolean isFiltered(SingleAccessLog saLog)
        {
                boolean isFiltered = false;
                for(Filters filter:filters)
                {
                        if(filter.isFiltered(saLog))
                        {
                                isFiltered = true;
                                break;
                        }
                }
                
                return isFiltered;
        }
}
